package com.cloudeasy.core.authorize;

import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 基本授权配置管理器
 */
@Component
public class BaseAuthorizeConfigManager implements AuthorizeConfigManager {
    /**
     * {@link AuthorizeConfigProvider}列表
     */
    private final List<AuthorizeConfigProvider> authorizeConfigProviders;

    public BaseAuthorizeConfigManager(List<AuthorizeConfigProvider> authorizeConfigProviders) {
        this.authorizeConfigProviders = authorizeConfigProviders;
    }

    /**
     * 让注册的{@link AuthorizeConfigProvider}都执行自己的配置逻辑
     *
     * @param config {@link ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry}配置对象
     */
    @Override
    public void config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config) {
        authorizeConfigProviders.forEach(authorizeConfigProvider -> {
            authorizeConfigProvider.config(config);
        });
    }
}
